using System.Web;

using System.Xml;
using System;

/*	-----------------------------------------------------------------------	
	Copyright:	umlungu consulting (pty) ltd
	Author:		Alan Benington	
	Started:	2006-03-08	
	Status:		release	
	Version:	1.0.3.20060329
	License:	GNU General Public License
	-----------------------------------------------------------------------	*/
	
namespace umlungu.engineX.blogX {
	/// <summary>
	/// Description of the x_page class.
	/// <para>This class ia a simple page class that loads an xml page from disk</para>
	/// </summary>
	public class x_page {
		#region Invisible properties
		private System.Web.UI.Page uipage;
		private const string basepath = "pages/";
		#endregion

		#region Error String constants
		private const string error_page_path = "Path to the page is not defined";
		#endregion

		#region Visible properties
		/// <summary>The element containing the page xml</summary>
		/// <value>The page XmlElement</value>
		public XmlElement Page {
			get { return (XmlElement)document.DocumentElement.SelectSingleNode("/content/page"); }
		}
		/// <summary>The element containing the content xml</summary>
		/// <value>The content XmlElement</value>
		public XmlElement Content {
			get { return (XmlElement)document.DocumentElement.SelectSingleNode("/content"); }
		}
		private XmlDocument document;
		/// <summary>The xml document containing the page</summary>
		/// <value>The page XmlDocument</value>
		public XmlDocument Document {
			get { return document; }
		}
		private string section;
		/// <summary>The section</summary>
		/// <value>The section to which the page belongs</value>
		public string Section {
			get { return section; }
			set { section = value; }
		}
		private string subsect;
		/// <summary>The Sub section</summary>
		/// <value>The sub-section to which the page belongs</value>
		public string Subsect {
			get { return subsect; }
			set { subsect = value; }
		}
		private string process;
		/// <summary>The process</summary>
		/// <value>The process to which the page belongs</value>
		public string Process {
			get { return process; }
			set { process = value; }
		}
		private string filename;
		/// <summary>The filename prefix (ie w/o '.xml')</summary>
		/// <value>The name of the file prefix</value>
		public string Filename {
			get { return filename; }
			set { filename = value; }
		}
		#endregion

		#region Constructors/Destructors
		/// <overloads>Constructor</overloads>
		/// <summary>Arbitary constructor</summary>
		public x_page() {
			document = new XmlDocument();
		}
		/// <summary>Default constructor</summary>
		/// <param name="thispage">The web application Page object</param>
		public x_page(System.Web.UI.Page thispage) : this() {
			uipage = thispage;
		}
		/// <summary>Constructor description</summary>
		/// <param name="thispage">The web application Page object</param>
		/// <param name="sect">The section</param>
		/// <param name="sub">The sub-section</param>
		/// <param name="proc">The process</param>
		/// <param name="file">The filename</param>
		public x_page(System.Web.UI.Page thispage, string sect, string sub, string proc, string file) : this(thispage) {
			Load(sect, sub, proc, file);
		}
		#endregion

		#region Public methods
		/// <overloads>Description of the overloaded example method</overloads>
		/// <summary>
		/// Path to page xml defined
		/// </summary>
		/// <param name="sect">The section</param>
		/// <param name="sub">The sub-section</param>
		/// <param name="proc">The process</param>
		/// <param name="file">The filename</param>
		public void Load(string sect, string sub, string proc, string file) {
			section = sect;
			subsect = sub;
			process = proc;
			filename = file;
			Load();
		}
		/// <summary>
		/// Assumes that the page parameters already set (section, subsect etc)
		/// </summary>
		public void Load() {
			Document.Load(filepath());
		}
		/// <summary>
		/// Assumes that the page parameters already set (section, subsect etc)
		/// </summary>
		/// <param name="filepath">full path to the page to be loaded</param>
		public void Load(string filepath) {
			Document.Load(filepath);
		}
		#endregion
		
		#region Protected methods
		/// <summary>
		/// Description of this method
		/// </summary>
		protected void _Example() {
		}
		#endregion
				
		#region Private methods
		/// <summary>
		/// Description of this method
		/// </summary>
		protected string filepath() {
			return(uipage.Server.MapPath(String.Concat(basepath, section, "/", subsect, "/", process, (process == "")? "" : "/", filename, ".xml")));
		}
		#endregion
	}
}
